<template>
	<view class="content">
		<view class="inner">
			<view class="info">
				<view class="info_item">
					<view class="item_title">类别名称：
						<view class="important">*</view>
					</view>
					<view class="item_input">
						<u--input border="none" placeholder="请输入类别名称" v-model="form.typeName" clearable></u--input>
					</view>

				</view>
			</view>
			<!-- 提交按钮 -->
			<view class="buttom">
				<u-button type="primary" text="提交" @click="handleSubmit"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		saveOrUpdateType,
		checkTypeOnly
	} from '../../api/laboratory.js'
	export default {
		data() {
			return {
				form: {
					typeName: ""
				},
				typeName: ""
			};
		},
		onLoad(options) {
			this.form.typeId = options.typeId
			this.typeName = options.typeName

		},

		mounted() {
			this.form.typeName = this.typeName
		},
		methods: {
			handleSubmit() {
				if (!this.form.typeName) {
					uni.$u.toast("实验室类别名称不能为空")
					return
				}
				checkTypeOnly({
					typeName: this.form.typeName
				}).then(res => {
					let isOnly = res.data.isOnly
					if (!isOnly) {
						uni.$u.toast("该类别名称已存在")
						return
					} else {
						saveOrUpdateType(this.form).then(res => {
							uni.$u.toast("操作成功！")
							setTimeout(() => {
								uni.navigateBack({
									url: "/subpages/admin_lab_type/admin_lab_type"
								})
							}, 500)
						}).catch(err => {
							uni.$u.toast("操作失败！")
						})
					}


				})

			}
		}

	}
</script>

<style lang="scss">
	.content {
		box-sizing: border-box;
		padding: 20upx;
		width: 100%;
		min-height: 100vh;
		background-color: #fff;
		padding-top: 65upx;

		.inner {
			position: relative;
			width: 100%;
			min-height: 30vh;
			background-color: #fff;
			box-shadow: 0 0 10px rgba(0, 0, 0, .15);
			border-radius: 15upx;

			.info {
				width: 100%;
				height: 95upx;

				.info_item {
					box-sizing: border-box;
					padding: 0 30upx;
					width: 100%;
					min-height: 95upx;
					background-color: #fff;
					border-bottom: 3upx solid #f1f1f1;
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: center;

					.item_title {
						position: relative;
						width: 200upx;
						font-weight: 600;

						.important {
							position: absolute;
							top: -2upx;
							left: -20upx;
							font-size: 36upx;
							color: red;


						}

					}

					.item_input {
						flex: 1;
						height: 100%;
						// margin-top: 7upx;
					}
				}
			}

			.buttom {
				box-sizing: border-box;
				padding: 0 20upx;
				position: absolute;
				bottom: 50upx;
				left: 0;
				width: 100%;
				height: 50upx;

			}
		}
	}
</style>